package ua.kpi.fpm.km61.strat.sp.st;

public class Symbol {

	private String name;
	private boolean declarated = false;
	private int blockLevel;
	private BlockType blockType;
	private boolean privateSymbol = false;
	private int firstIndex;
	private int lastIndex;
	
	public Symbol() {
		super();
	}
	
	public Symbol(String name, boolean declarated, Block block) {
		super();
		this.name = name;
		this.declarated = declarated;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public boolean isDeclarated() {
		return declarated;
	}

	public void setDeclarated(boolean initialized) {
		this.declarated = initialized;
	}

	public boolean isAlive(int pos) {
		if (pos < this.firstIndex) {
			throw new RuntimeException("Undeclared variable (lexem "+(pos+1)+")");
		}
		if (pos > this.lastIndex) {
			throw new RuntimeException("Unexisting variable (lexem "+(pos+1)+")");
		}
		return true;
	}

	@Override
	public String toString() {
		return name;
	}

	public int getBlockLevel() {
		return blockLevel;
	}

	public void setBlockLevel(int blockLevel) {
		this.blockLevel = blockLevel;
	}

	public BlockType getBlockType() {
		return blockType;
	}

	public void setBlockType(BlockType blockType) {
		this.blockType = blockType;
	}

	public boolean isPrivateSymbol() {
		return privateSymbol;
	}

	public void setPrivateSymbol(boolean privateSymbol) {
		this.privateSymbol = privateSymbol;
	}

	/**
	 * @return the firstIndex
	 */
	public int getFirstIndex() {
		return firstIndex;
	}

	/**
	 * @param firstIndex the firstIndex to set
	 */
	public void setFirstIndex(int firstIndex) {
		this.firstIndex = firstIndex;
	}

	/**
	 * @return the lastIndex
	 */
	public int getLastIndex() {
		return lastIndex;
	}

	/**
	 * @param lastIndex the lastIndex to set
	 */
	public void setLastIndex(int lastIndex) {
		this.lastIndex = lastIndex;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		Symbol other = (Symbol) obj;
		if (name == null) {
			if (other.name != null) {
				return false;
			}
		} else if (!name.equals(other.name)) {
			return false;
		}
		return true;
	}
	
	
	
}